home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume89
/
aplictns
/
hyphelp.2
< prev
next >
Wrap
Internet Message Format
|
1989-10-25
|
63KB
Path: xanth!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!apple!sun-barr!newstop!sun!swap!page
From: page%swap@Sun.COM (Bob Page)
Newsgroups: comp.sources.amiga
Subject: v89i188: hyperhelp - amiga help system, Part02/03
Message-ID: <126802@sun.Eng.Sun.COM>
Date: 25 Oct 89 17:05:44 GMT
Sender: news@sun.Eng.Sun.COM
Lines: 2235
Approved: page@sun.com
Submitted-by: jap@syssun.cl.msu.edu (Joe A. Porkka)
Posting-number: Volume 89, Issue 188
Archive-name: applications/hyphelp.2
# This is a shell archive.
# Remove anything above and including the cut line.
# Then run the rest of the file through 'sh'.
# Unpacked files will be owned by you and have default permissions.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: SHell ARchive
# Run the following text through 'sh' to create:
# gc2.c
# gen.c
# getenv.c
# getfile.c
# grandcentral.c
# help.h
# This is archive 2 of a 3-part kit.
# This archive created: Wed Oct 25 10:02:51 1989
echo "extracting gc2.c"
sed 's/^X//' << \SHAR_EOF > gc2.c
X/* These functions should be in grandcentral.c */
X
X#include <intuition/intuition.h>
X#include <exec/io.h>
X#include <exec/memory.h>
X#include "help.h"
X#include "helptext.h"
X
Xextern struct NewWindow nw;
Xextern int debug, stdout;
Xextern struct Screen *screen;
Xextern struct MsgPort *mp;
X
Xextern ULONG ENVRefresh, ENVNumClicks, ENVAskFirst;
Xextern struct Task *mytask;
X
X/* From print.c */
Xextern struct IOStdReq *printreq;
X/* grandcentral.c */
Xextern short openroot, closeall, hideall, goaway, findabout, checkflags;
Xextern int printing, printbuflen;
Xextern u_char *printbuf;
Xextern struct openwindows *printow;
X
X#define SETREFRESH(ow) ((struct openwindows *)ow)->flags|=ow_REFRESH
X#define CLRREFRESH(ow) ((struct openwindows *)ow)->flags&=~ow_REFRESH
X
Xextern ULONG prevsecs, prevmicros;
Xextern u_short clickx, clicky, clickcount;
Xextern struct key key;
X
XULONG lastclicksecs, lastclickmicros;
X
X/* flipwindow()
X Flip a window between icon and full size.
X Also can be used to re-open hidden windows.
X*/
Xint
Xflipwindow(tmpow,flag)
X struct openwindows *tmpow;
X int flag; /* 0==flip window, 1==re-open window */
X{
X short left, top, wide, high;
X
X nw.Screen=screen;
X SETREFRESH(tmpow);
X if(tmpow->window) {
X getdims(tmpow);
X left=tmpow->LeftEdge,
X top =tmpow->TopEdge,
X wide=tmpow->Width,
X high=tmpow->Height;
X
X#ifdef DEBUG1
X dmsg(1,"flip window\n");
X#endif
X CWS(tmpow->window, tmpow->doc->savefont);
X tmpow->window=0;
X nw.LeftEdge=tmpow->saveleft;
X nw.TopEdge=tmpow->savetop;
X nw.Width=tmpow->savewide;
X nw.Height=tmpow->savehigh;
X
X tmpow->saveleft=left;
X tmpow->savetop=top;
X tmpow->savewide=wide;
X tmpow->savehigh=high;
X } else {
X#ifdef DEBUG1
X dmsg(1,"Open hidden window\n");
X#endif
X nw.LeftEdge=tmpow->LeftEdge;
X nw.TopEdge=tmpow->TopEdge;
X nw.Width=tmpow->Width;
X nw.Height=tmpow->Height;
X nw.MinWidth=tmpow->MinWidth;
X nw.MinHeight=tmpow->MinHeight;
X }
X
X /* Open full size window if ICONIZED or hidden and !iconized */
X if( (flag && !(tmpow->flags & ow_ICONIZED)) || ((!flag) && (tmpow->flags & ow_ICONIZED)) ) {
X#ifdef DEBUG1
X dmsg(1,"OPEN BIG WINDOW\n");
X#endif
X if(!flag) {
X nw.MinWidth=tmpow->saveminwidth;
X nw.MinHeight=tmpow->saveminheight;
X }
X nw.DetailPen=-1;
X nw.BlockPen=-1;
X nw.Flags=HELPWINDOWFLAGS | ENVRefresh;
X nw.Title=tmpow->doc->body->comment;
X nw.FirstGadget=tmpow->scroll;
X tmpow->scroll->NextGadget=tmpow->up;
X tmpow->up->NextGadget=tmpow->down;
X tmpow->down->NextGadget=0;
X tmpow->icon->NextGadget=0;
X tmpow->window=OpenWindow(&nw);
X if(tmpow->window==0) {
X#ifdef DEBUG5
X dmsg(5,"OPEN BIG WINDOW failed!\n");
X#endif
X return 0;
X }
X tmpow->window->UserPort=mp;
X ModifyIDCMP(tmpow->window, HELPWINDOWIDCMPFLAGS);
X AddGadget(tmpow->window,tmpow->icon,0); /* Put the ICON gadget at the head of the class */
X RefreshGList(tmpow->icon,tmpow->window,0,1); /* ...and make it appear */
X SetDrMd(tmpow->window->RPort,JAM1);
X if(tmpow->doc->savefont) SetFont(tmpow->window->RPort,tmpow->doc->savefont);
X tmpow->window->UserData=(BYTE *)tmpow;
X if(!flag) tmpow->flags &= ~ow_ICONIZED;
X if((tmpow->doc->linespace+tmpow->window->RPort->Font->tf_YSize)*3 < tmpow->window->MinHeight) {
X tmpow->window->RPort->TxHeight=tmpow->window->RPort->Font->tf_YSize+tmpow->doc->linespace;
X }
X makemenu(tmpow->window);
X } else {
X#ifdef DEBUG1
X dmsg(1,"OPEN ICON WINDOW\n");
X#endif
X nw.DetailPen=0;
X nw.BlockPen=3;
X nw.Flags=HELPICONWINDOWFLAGS;
X nw.FirstGadget=0;
X nw.Title=tmpow->doc->body->comment;
X nw.MinHeight=2;
X nw.MinWidth=2;
X tmpow->window=OpenWindow(&nw);
X if(tmpow->window==0) {
X#ifdef DEBUG5
X dmsg(5,"OPEN ICON WINDOW failed!\n");
X#endif
X return 0;
X }
X tmpow->window->UserPort=mp;
X ModifyIDCMP(tmpow->window, HELPICONWINDOWIDCMPFLAGS);
X AddGadget(tmpow->window,tmpow->icon,0); /* Put the ICON gadget at the head of the class */
X RefreshGList(tmpow->icon,tmpow->window,0,1); /* ...and make it appear */
X tmpow->window->UserData=(BYTE *)tmpow;
X if(!flag) tmpow->flags |= ow_ICONIZED;
X makemenu(tmpow->window);
X }
X getdims(tmpow);
X return 1;
X}
X
Xvoid
Xgetdims(tmpow)
X struct openwindows *tmpow;
X{
X LockLayerRom(tmpow->window->WLayer);
X tmpow->Height = tmpow->window->Height;
X tmpow->Width = tmpow->window->Width;
X tmpow->LeftEdge = tmpow->window->LeftEdge;
X tmpow->TopEdge = tmpow->window->TopEdge;
X tmpow->MinWidth= tmpow->window->MinWidth;
X tmpow->MinHeight= tmpow->window->MinHeight;
X UnlockLayerRom(tmpow->window->WLayer);
X}
X
Xvoid
Xscrollit(ow)
X struct openwindows *ow;
X{
X int line;
X line= (((struct PropInfo *)ow->scroll->SpecialInfo)->VertPot*(ow->doc->l_count - ow->high)) >>16;
X moveto(ow,line);
X SETREFRESH(ow);
X}
X
X/*
Xvoid
Xcancelprintjob() {
X printitout();
X if(printing) {
X dmsg(1,"Cancel print job! printing=%ld\n",printing);
X printing=0;
X if(printow) {
X closewindow(printow);
X printow=0;
X dmsg(1,"About to dnit print\n");
X printdnit();
X }
X dmsg(1,"About to free printbuffer...");
X if(printbuf && printbuflen) FreeMem(printbuf,printbuflen);
X printbuf=0;
X printbuflen=0;
X dmsg(1,"Freed!\n");
X } else {
X dmsg(1,"CANCEL PRINT WHILE NOT PRINTING==0!\n");
X }
X printitout();
X}
X*/
Xvoid checkclicks(im,tmpow)
X struct IntuiMessage *im;
X struct openwindows *tmpow;
X{
X if (!(im->Seconds>lastclicksecs || (im->Seconds==lastclicksecs && im->Micros>=lastclickmicros))) {
X return; /* Avoid allowing user to accidently (or purposely)doubleclick a second time on something,
X before we get to take care of the first
X */
X }
X if(prevsecs==0) {
X clickcount=1;
X clickx=im->MouseX;
X clicky=im->MouseY;
X }
X if( ((clickx-im->MouseX)*(clickx-im->MouseX)+
X (clicky-im->MouseY)*(clicky-im->MouseY))
X <
X ((tmpow->window->RPort->TxHeight)*(tmpow->window->RPort->TxHeight))
X ) {
X if(DoubleClick(prevsecs,prevmicros,im->Seconds,im->Micros) || ENVNumClicks==1) {
X clickcount++;
X if(clickcount>=ENVNumClicks) {
X clickcount=0;
X prevsecs=0; /* Prevent triple clicks */
X#ifdef DEBUG1
X dmsg(1,"SELECT CLICK\n");
X#endif
X findword(tmpow,(int)im->MouseX,(int)im->MouseY, &key);
X if(key.name) {
X#ifdef DEBUG1
X dmsg(1,"Type is ");
X#endif
X if(key.type) {
X int len;
X u_char *tmpcmd;
X
X dmsg(1,"execute '%s'",key.name);
X if(askforexec(tmpow->window,key.name)) {
X len=strlen(key.name)+17;
X tmpcmd=(u_char *)AllocMem(len,0);
X if(tmpcmd) {
X strncpy(tmpcmd,"run <nil: >nil: ",17);
X strncpy(tmpcmd+16,key.name,len);
X Execute(tmpcmd,0,stdout);
X#ifdef DEBUG1
X dmsg(1,"\nReturncode==%ld\n",IoErr());
X#endif
X if(tmpcmd) FreeMem(tmpcmd,len);
X } else {
X#ifdef DEBUG5
X dmsg(5,"** Out-of-mem, could not execute!\n");
X#endif
X }
X CurrentTime(&lastclicksecs,&lastclickmicros);
X } else {
X dmsg(1,"Execute aborted!\n");
X DisplayBeep(tmpow->window->WScreen);
X }
X } else {
X struct openwindows *tmpow2;
X u_char *tmpname, len;
X#ifdef DEBUG1
X dmsg(1,"reference");
X dmsg(1,".\nFileName='%s'\n",key.name);
X dmsg(1,"Opening up the reference\n");
X#endif
X tmpname=strchr(key.name,(u_char)',');
X if(tmpname) {
X len=tmpname-key.name-1; /*Length of label*/
X while(*tmpname==' ' || *tmpname=='\t') tmpname++;
X tmpow2=getfile(tmpname);
X } else {
X tmpow2=getfile(key.name);
X }
X CurrentTime(&lastclicksecs,&lastclickmicros);
X if(tmpow2==0) {
X#ifdef DEBUG1
X dmsg(1,"Could not open referenced file.\n");
X#endif
X DisplayBeep(tmpow->window->WScreen);
X } else {
X tmpow=tmpow2;
X if(tmpname) {
X#ifdef DEBUG1
X dmsg(1,"GOTO ");
X#endif
X if(tmpow->doc->labs && tmpow->doc->lab_count) {
X int j;
X#ifdef DEBUG1
X if(debug) {
X int i;
X dmsg(1,"Searching for label '");
X for(i=0;i<len;i++) dmsg(1,"%lc",key.name[i]);
X dmsg(1,"'.\n");
X }
X#endif
X for(j=0;j<tmpow->doc->lab_count;j++) {
X if(strnicmp(key.name,tmpow->doc->labs[j].name,len)==0) {
X tmpow->doc->pnum=tmpow->doc->labs[j].paragraph;
X tmpow->doc->lnum=tmpow->doc->labs[j].line;
X fixscrollgadget(tmpow);
X#ifdef DEBUG1
X dmsg(1,"Found!, pnum=%ld, lnum=%ld.\n",tmpow->doc->pnum, tmpow->doc->lnum);
X#endif
X break;
X }
X }
X }
X }
X refresh(tmpow);
X }
X }
X if(key.length) {
X#ifdef DEBUG1
X dmsg(1,"Freeing memory for key==%ld.\n",key.length);
X#endif
X FreeMem(key.name,key.length);
X key.length=0;
X }
X } else {
X#ifdef DEBUG1
X dmsg(1,"FileName='<nil>'.\n");
X#endif
X }
X } else {
X prevsecs=im->Seconds;
X prevmicros=im->Micros;
X }
X } else {
X prevsecs=im->Seconds;
X prevmicros=im->Micros;
X clickcount=1;
X }
X } else {
X clickcount=0;
X prevsecs=prevmicros=0;
X }
X}
X
Xvoid
Xprocessmenuevent(menunumber,MenuStrip, tmpow)
X USHORT menunumber;
X struct Menu *MenuStrip;
X struct openwindows *tmpow;
X{
X struct MenuItem *item, *ItemAddress();
X if(menunumber!=MENUNULL) {
X
X while(menunumber!=MENUNULL) {
X item=ItemAddress(MenuStrip,menunumber);
X#ifdef DEBUG1
X dmsg(1,"Menu menunumber=%lx.\n",menunumber);
X dmsg(1,"Menu==%ld, Item=%ld, SubItem=%ld",
X MENUNUM(menunumber), ITEMNUM(menunumber), SUBNUM(menunumber));
X#endif
X
X switch(MENUNUM(menunumber)) {
X case 0: /* MENU: Control */
X switch(ITEMNUM(menunumber)) {
X case 0: /* ITEM: Open A file */
X#ifdef DEBUG1
X dmsg(1,"Open a file -- Not Implemented yet!\n");
X#endif
X break;
X case 1: /* ITEM: Open root file */
X#ifdef DEBUG1
X dmsg(1,"Open root file!\n");
X#endif
X openroot=1;
X checkflags++;
X break;
X case 2: /* ITEM: Close all windows */
X#ifdef DEBUG1
X dmsg(1,"Close selected!\n");
X#endif
X closeall=1;
X checkflags++;
X break;
X case 3: /* ITEM: Hide all windows */
X#ifdef DEBUG1
X dmsg(1,"Hide selected!\n");
X#endif
X hideall=1;
X break;
X case 4: /* ITEM: Go away completely */
X#ifdef DEBUG1
X dmsg(1,"Go away\n");
X#endif
X goaway=1;
X break;
X case 5: /* ITEM: About */
X dmsg(1,"About\n");
X findabout=1;
X break;
X }
X break;
X case 1: /* MENU: Print */
X switch(ITEMNUM(menunumber)) {
X case 0: /* ITEM: Print window */
X checkflags++;
X tmpow->flags|= ow_PRINTWINDOW;
X break;
X case 1: /* ITEM: Print file */
X checkflags++;
X tmpow->flags|= ow_PRINTFILE ;
X break;
X case 2: /* ITEM: Cancel prints */
X if(printing) printing=6;
X break;
X }
X break;
X
X }
X menunumber=item->NextSelect;
X }
X
X } else {
X#ifdef DEBUG1
X dmsg(1,"No menu pick.\n");
X#endif
X }
X}
SHAR_EOF
echo "extracting gen.c"
sed 's/^X//' << \SHAR_EOF > gen.c
X/* HyperHelp -- Copyright 1989 Joe Porkka */
X
X/* gen.c -- General usage routines. Some are duplicates from the
X standard C library, but are duplicated here to avoid
X linking with the C library.
X*/
X
Xchar *arg(len,str)
X register int *len;
X register char **str;
X{
X register int x;
X register char *s,*a,quote=0;
X
X x=*len; s=*str;
X while(x>=0 && (*s==' ' || *s=='\t' || *s=='\n')) {x--; s++;}
X if(*s=='\'' || *s=='"') {quote=*s++; x--;}
X a=s;
X if(quote) {
X while(x>=0 && (*s!='\'' && *s!='"')) {x--;s++;}
X } else {
X while(x>=0 && (*s!=' ' && *s!='\t' && *s!='\n')) {x--; s++;}
X }
X *s=0;
X *str=s+1;
X *len=x;
X return(a);
X}
X
Xchar *
Xstrchr(s,c)
X register char *s,c;
X{
X if(s==0) return 0;
X while(*s!=0) if(*s++==c) return s;
X return 0;
X}
X
Xint
Xstrncpy(to,from,max)
X register char *to, *from;
X register int max;
X{
X register int k;
X
X for(k=0;k<max;k++)
X if( ( *to++ = *from++ )==0) break;
X return k;
X}
X
Xint
Xstrlen(to)
X register char *to;
X{
X register int x=0;
X while(*to++) x++;
X return (x);
X}
X
Xstrcmp(this,that)
X register char *this, *that;
X{
X register int i,j;
X
X if(this==0 && that==0) return(0);
X i=strlen(this);
X j=strlen(that);
X while(*this++==*that++ && i>0 && j>0) {
X i--; j--;
X };
X if(i==0 && j==0) return(0);
X if( *--this < *--that ) return(-1);
X if( *this>*that ) return(1);
X if(i) return(1); else return(-1);
X}
X
Xint
Xstrnicmp(this,that,n)
X register char *this, *that;
X register int n;
X{
X register int i=0;
X register char a,b;
X
X if(this==0 && that==0) return(0);
X while(i<n) {
X a=*this++;
X b=*that++;
X if(a!=b) {
X if(a==0) return -1;
X if(b==0) return 1;
X if(a>='a' && a<='z')
X a-=32;
X if(b>='a' && b<='z')
X b-=32;
X
X if(a!=b) break;
X } else if(a==0) return 0;
X i++;
X };
X return (int) (a-b);
X}
X
Xint
Xstrfind(str,what)
X char *str, *what;
X{
X register char a,b, *pos, *pat;
X
X if(str==0 && what==0 || what==0) return(0);
X for(pos=str; *pos!=0; pos= ++str) {
X pat=what;
X while( (b=*pat++)!=0 ) {
X a=*pos++;
X if(a==0) return 1;
X if(a!=b) {
X if(a>='a' && a<='z')
X a-=32;
X if(b>='a' && b<='z')
X b-=32;
X
X if(a!=b) break;
X }
X }
X if(b==0) return 0;
X }
X return 1;
X}
SHAR_EOF
echo "extracting getenv.c"
sed 's/^X//' << \SHAR_EOF > getenv.c
X/* HyperHelp -- Copyright 1989 Joe Porkka */
X
X/* getenv.c -- reads the ENV: vars into internal variables */
X
X#include <exec/types.h>
X#include <exec/tasks.h>
X#include <graphics/text.h>
X#include <exec/memory.h>
X#include <libraries/dosextens.h>
Xextern struct Task *mytask;
X#define MEMF_NAMED 0x10000000
X#define AllocMem allocmem
X#define FreeMem freemem
X
X
X/* DESCRIPTION OF ENV: VARIABLES:
X ==============================
X
X * NoSetFont If this exists, then the FONT directive in files
X will be ignored.
X
X * Font = name.font n Sets the default font for files that do not specify
X a font. If NoSetFont exists, then all files will
X use this font.
X
X * HotKey = code,qual Sets the hotkey to scancode 'code' with
X 'qual' qualifiers (exclusively) set.
X
X * RootFile = path Sets what the root of the helpfiles are.
X This defaults to "help:toplevel"
X
X * Screen = Can be set to WBENCHSCREEN or CUSTOMSCREEN.
X
X * Pen = n Sets the default text pen color.
X
X * Paper = n Sets the default 'paper' color.
X
X * Top Sets the default position
X * Left and size of help windows.
X * Width These values are range checked
X * Height for safeties sake.
X
X * XInc Sets the X and Y increments to offset
X * YInc windows to avoid overlaps.
X
X*/
X
X#define HELPCODE 0x5f
X#define HELPQUAL 0x0040
X#define ENVBUFSIZE 100
X#define ROOTFILE "help:toplevel"
X
Xchar *envbuf;
X
Xint NoSetFont, NoHotKey, ScreenType, ENVAskFirst;
X
Xunsigned int HotKeyCode, HotKeyQual, PenColor;
Xint ENVTop, ENVLeft, ENVWidth, ENVHeight, ENVXInc, ENVYInc;
Xint ENVLspace,ENVNumClicks;
Xunsigned char *ENVRootFile, *ENVIndexFile;
Xstruct TextAttr *ENVFont;
Xunsigned long ENVRefresh;
X
Xint nsetflag ;
Xextern int oserr;
Xextern int debug;
X
Xint
Xgetenv() {
X int length;
X struct Process *myproc=(struct Process *)mytask;
X APTR tmpptr;
X
X oserr=0;
X NoSetFont=0; NoHotKey=0;
X ENVAskFirst=1;
X ENVFont=0;
X PenColor=-1;
X ScreenType=0; /* WBenchscreen */
X
X envbuf=(char *)AllocMem(ENVBUFSIZE,0);
X if(envbuf==0) return 0;
X
X /* Disable the "Insert Volume ENV:" garbage */
X tmpptr=myproc->pr_WindowPtr;
X#ifdef DEBUG1
X dmsg(1,"Process WindowPtr=0x%lx.\n",myproc->pr_WindowPtr);
X#endif
X myproc->pr_WindowPtr= (APTR)-1; /* keep the requesters away */
X HotKeyCode = getnumvar("ENV:HELPHotKeyCode");
X if(oserr==218) {
X /* If ENV: not mounted, then don't keep trying to access it */
X FreeMem(envbuf,ENVBUFSIZE);
X envbuf=0;
X HotKeyCode= HELPCODE;
X HotKeyQual= HELPQUAL;
X myproc->pr_WindowPtr=tmpptr;
X return 0;
X }
X ENVAskFirst=0; /* Make it default to on, unless there is an envronment */
X if(oserr==205) { /* File did not exist */
X HotKeyCode= HELPCODE;
X }
X HotKeyQual = getnumvar("ENV:HELPHotKeyQual");
X if(oserr==205) { /* File did not exist */
X HotKeyQual= HELPQUAL;
X }
X PenColor = getnumvar("ENV:HELPPenColor");
X if(oserr==205) {
X#ifdef DEBUG5
X dmsg(5,"OSERR=205, pencolor=%ld\n",PenColor);
X#endif
X PenColor=-1;
X }
X if(PenColor==0) PenColor=1;
X#ifdef DEBUG1
X dmsg(1,"GETENV: Pencolor=%ld\n",PenColor);
X#endif
X ENVTop = getnumvar("ENV:HELPTop");
X ENVLeft = getnumvar("ENV:HELPLeft");
X ENVWidth = getnumvar("ENV:HELPWidth");
X ENVHeight = getnumvar("ENV:HELPHeight");
X ENVXInc = getnumvar("ENV:HELPXInc");
X ENVYInc = getnumvar("ENV:HELPYInc");
X ENVLspace = getnumvar("ENV:HELPLspace");
X ENVNumClicks = getnumvar("ENV:HELPNumClicks");
X if(ENVNumClicks<1 || ENVNumClicks >4) ENVNumClicks=2;
X
X length = getvar("ENV:HELPSCREEN");
X if(length) {
X#ifdef DEBUG1
X /* dmsg(1,"Screen = '%s'\n",envbuf); */
X#endif
X if(strfind(envbuf,"custom")==0) {
X ScreenType=1;
X }
X if(strfind(envbuf,"interlace")==0) {
X ScreenType|=2;
X }
X }
X length = getvar("ENV:HELPREFRESH");
X if(length) {
X if(strnicmp("smart_refresh",envbuf,13)==0 || strnicmp("smart",envbuf,5)==0) {
X ENVRefresh=1;
X }
X }
X
X length=getvar("ENV:HELPNoSetFont");
X if(length==-1)
X NoSetFont=0;
X else
X NoSetFont=1;
X
X length=getvar("ENV:HELPAskFirst");
X if(length==-1)
X ENVAskFirst=0;
X else
X ENVAskFirst=1;
X
X length=getvar("ENV:HELPNoHotKey");
X if(length==-1)
X NoHotKey=0;
X else
X NoHotKey=1;
X
X length=getvar("ENV:HELPFont");
X if(length==-1) {
X ENVFont=0;
X } else {
X int j,t;
X
X envbuf[length]=0;
X for(j=0;envbuf[j]!=0 && envbuf[j]!=' ';j++);
X ENVFont=(struct TextAttr *)AllocMem(sizeof(struct TextAttr),MEMF_CLEAR | MEMF_NAMED,"getenv TextAttr");
X if(ENVFont) {
X ENVFont->ta_Name = (STRPTR) AllocMem(j,0|MEMF_NAMED,"getenv fontname");
X if(ENVFont->ta_Name) {
X strncpy(ENVFont->ta_Name,envbuf,j);
X ENVFont->ta_Name[j]=0;
X
X dmsg(1,"getenv: Font name is '%s'\t",ENVFont->ta_Name);
X
X while(envbuf[j]==' ')j++;
X t=0;
X while(envbuf[j]<='9' && envbuf[j]>='0') {
X t=t*10+ envbuf[j]-'0';
X j++;
X }
X ENVFont->ta_YSize=t;
X
X dmsg(1,"getenv: Font height =%ld.\n",t);
X
X } else {
X FreeMem(ENVFont,sizeof(struct TextAttr));
X ENVFont=0;
X }
X }
X }
X length=getvar("ENV:ENVRootFile");
X if(length==-1) {
X ENVRootFile=0;
X } else {
X envbuf[length]=0;
X ENVRootFile=(char *)AllocMem(length+1,0);
X if(ENVRootFile) strncpy(ENVRootFile,envbuf,length+1);
X }
X length=getvar("ENV:ENVIndexFile");
X if(length==-1) {
X ENVIndexFile=0;
X } else {
X envbuf[length]=0;
X ENVIndexFile=(char *)AllocMem(length+1,0);
X if(ENVIndexFile) strncpy(ENVIndexFile,envbuf,length+1);
X }
X
X#ifdef DEBUG1
X /* dmsg(1,"Done.\n"); */
X#endif
X FreeMem(envbuf,ENVBUFSIZE);
X envbuf=0;
X myproc->pr_WindowPtr=tmpptr;
X return -1;
X}
X
Xint
Xgetnumvar(name)
X char *name;
X{
X long length;
X
X length=getvar(name);
X#ifdef DEBUG1
X /* dmsg(1,"Getenv(%s)=",name); */
X#endif
X if (length==-1) {
X#ifdef DEBUG1
X /* dmsg(1,"<nil>\n"); */
X#endif
X return 0;
X }
X#ifdef DEBUG1
X /* dmsg(1,"'%s' ",envbuf); */
X#endif
X return(getint(envbuf));
X}
X
Xint
Xgetvar(name)
X char *name;
X{
X long fh, len;
X
X oserr=0;
X fh=Open(name,1005);
X if(fh==0) {
X oserr=IoErr();
X return -1; /* value did not exist */
X }
X
X len=Read(fh,envbuf,ENVBUFSIZE);
X if(len==ENVBUFSIZE) len--;
X envbuf[len]=0; /* It must be NULL terminated */
X Close(fh);
X return len;
X}
X
Xint
Xgetint(str)
X char *str;
X{
X int val=0;
X int base=10;
X
X while (*str==' ' || *str=='\t') str++;
X if(*str=='0') {
X base=8;
X str++;
X if(*str=='x' || *str=='X') {
X base=16;
X str++;
X }
X }
X while(*str!=0) {
X if( (base==10 && *str>='0' && *str<='9') || ( base==8 && *str>='0' && *str<='7'))
X val = val*base + (*str) - '0';
X else if (base==16) {
X if(*str>='0' && *str<='9')
X val = val*16 + (*str) - '0';
X else {
X *str &= ~32;
X if(*str>='A' && *str<='F')
X val = val*16 + (*str) - (10+'A');
X }
X } else
X break;
X str++;
X }
X dmsg(1,"VAL=%ld.\n",val);
X return val;
X}
X
SHAR_EOF
echo "extracting getfile.c"
sed 's/^X//' << \SHAR_EOF > getfile.c
X/* HyperHelp -- Copyright 1989 Joe Porkka */
X
X/* getfile.c -- Reads a file into memory + prepares it for use */
X
X#include <exec/types.h>
X#include <exec/io.h>
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include <graphics/text.h>
X#include <intuition/intuition.h>
X#include "help.h"
X#include "helptext.h"
X#include "style.h"
X
Xextern int debug;
Xextern long oserr;
Xextern struct DOSerror errortext[];
Xextern struct List windowhead;
Xextern short screenWIDTH, screenHEIGHT;
X
X/* ENV: variables */
Xextern int ENVTop, ENVLeft, ENVWidth, ENVHeight, ENVXInc, ENVYInc;
Xextern int NoSetFont;
Xextern struct TextAttr *ENVFont;
X/**/
X
Xextern int TOP,LEFT,WIDTH,HEIGHT,XINC,YINC; /* FROM windows.c */
Xint sleft, stop, swidth, sheight;
X
Xstruct openwindows *
Xgetprintfile(name,wide)
X int wide;
X u_char *name;
X{
X struct doc *doc;
X struct openwindows *ow;
X
X doc=getdatafile(name);
X if(doc==0) {
X#ifdef DEBUG1
X dmsg(1,"getdatafile returns 0\n");
X#endif
X return(0);
X }
X ow=(struct openwindows *)AllocMem(sizeof(struct openwindows),MEMF_CLEAR|MEMF_NAMED,"getfile1");
X if(ow==0) {
X#ifdef DEBUG5
X dmsg(5,"OW IS ZERO!\n");
X#endif
X freefile(doc);
X return(0);
X }
X ow->doc=doc;
X
X AddTail(&windowhead,ow);
X
X ow->doc->pnum=0; ow->doc->lnum=0;
X
X if(format(doc,wide,0)==0) {
X closewindowsafely(ow);
X ow->window=0;
X Remove(ow);
X freefile(ow->doc);
X FreeMem(ow,sizeof(struct openwindows) );
X return(0);
X }
X return(ow);
X}
X
Xstruct openwindows *
Xgetfile(name)
X u_char *name;
X{
X struct doc *doc;
X struct Window *win;
X struct openwindows *ow;
X int top,left,width,height;
X doc=getdatafile(name);
X if(doc==0) {
X#ifdef DEBUG1
X dmsg(1,"getdatafile returns 0\n");
X#endif
X return(0);
X }
X ow=(struct openwindows *)AllocMem(sizeof(struct openwindows),MEMF_CLEAR|MEMF_NAMED,"getfile1");
X if(ow==0) {
X#ifdef DEBUG5
X dmsg(5,"OW IS ZERO!\n");
X#endif
X freefile(doc);
X return(0);
X }
X ow->doc=doc;
X if(sleft!=-1) {
X left=sleft;
X top=stop;
X width=swidth;
X height=sheight;
X } else {
X if(LEFT+WIDTH>=screenWIDTH) {
X ENVLeft+=ENVXInc;
X if(ENVLeft+WIDTH>screenWIDTH) ENVLeft=0;
X LEFT=ENVLeft;
X }
X if(TOP+HEIGHT>=screenHEIGHT) {
X ENVTop+=ENVYInc;
X if(ENVTop+HEIGHT>screenHEIGHT) ENVTop=0;
X TOP=ENVTop;
X }
X top=TOP;
X left=LEFT;
X width=WIDTH;
X height=HEIGHT;
X }
X#ifdef DEBUG1
X dmsg(1,"Makeing window (%ld,%ld,%ld,%ld)\n",left,top,width,height);
X#endif
X win=makewindow(ow,left,top,width,height,doc->body->comment,&doc->body->font);
X if(win==0) {
X#ifdef DEBUG5
X dmsg(5,"Makewindow failed!\n");
X#endif
X freefile(doc);
X FreeMem(ow,sizeof(struct openwindows));
X return(0);
X }
X if(ow->doc->linespace+win->RPort->TxHeight < win->MinHeight/3) {
X win->RPort->TxHeight+=ow->doc->linespace;
X }
X if(sleft==-1) {
X LEFT+=ENVXInc;
X TOP+=ENVYInc;
X }
X AddTail(&windowhead,ow);
X
X win->UserData=(BYTE *)ow;
X ow->doc->pnum=0; ow->doc->lnum=0;
X
X /* if(ow->doc->savefont) { */
X
X if(sizewindow(win)==0) {
X closewindowsafely(ow);
X ow->window=0;
X Remove(ow);
X freefile(ow->doc);
X FreeMem(ow,sizeof(struct openwindows) );
X return(0);
X }
X return(ow);
X}
X
Xstruct doc *
Xgetdatafile(filename)
X u_char *filename;
X{
X struct doc *doc, *tmp;
X
X#ifdef DEBUG1
X /* dmsg(1,"File name='%s'\n",filename); */
X#endif
X if( (doc=readfile(filename))==0) {
X#ifdef DEBUG1
X dmsg(1,"getfile: Open failed, returncode=%ld\n",oserr);
X#endif
X goto fail;
X }
X tmp=pbreakfile(doc);
X if(tmp==0) {
X#ifdef DEBUG1
X dmsg(1,"getfile: Format data failed\n");
X#endif
X goto fail;
X }
X
X return(doc);
X
Xfail:
X if(doc) {freefile(doc); doc=0;}
X if(oserr) {
X#ifdef DEBUG5
X dmsg(5,"getfile: error %ld, %s\n",oserr,errortext[errnum(oserr)].text);
X#endif
X }
X return(0);
X}
X
Xstruct doc *
Xreadfile(name)
X u_char *name;
X{
X struct FileInfoBlock *fileinfo=0;
X struct Lock *lock=0,*Lock(); /* to get info about the disk */
X struct doc *doc=0;
X int i;
X long len, fh=0, Open();
X struct openwindows *ow;
X
X oserr=103;
X len=strlen(name)+1; /* Make sure that we compare the \0 at the end too */
X if( (doc=(struct doc *)AllocMem(sizeof(struct doc),MEMF_CLEAR|MEMF_NAMED,"readfile2"))==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not get doc mem=%ld\n",AvailMem(0));
X#endif
X goto fail;
X }
X for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
X if( strnicmp(ow->doc->body->filename,name,len)==0) {
X (*doc)=(*ow->doc);
X doc->labs=0;
X doc->p=(struct paragraph *)AllocMem(doc->p_count * sizeof(struct paragraph),MEMF_CLEAR|MEMF_NAMED,"Copy of doc");
X if(doc->p==0) {
X doc->body=0;
X goto fail;
X }
X for(i=0;i<doc->p_count;i++) {
X doc->p[i].pindent = ow->doc->p[i].pindent;
X doc->p[i].indent = ow->doc->p[i].indent;
X doc->p[i].data = ow->doc->p[i].data;
X doc->p[i].length = ow->doc->p[i].length;
X }
X doc->body->usecount++;
X doc->pnum=doc->lnum=0;
X doc->savefont=0;
X break;
X }
X }
X if(!doc->body) {
X if( (fileinfo=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),0|MEMF_NAMED,"readfile1"))==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not get FileInfoBlock mem=%ld\n",AvailMem(0));
X#endif
X goto fail;
X }
X if( (lock=Lock(name,ACCESS_READ))==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not get lock\n");
X#endif
X oserr=IoErr();
X goto fail;
X }
X if(0==Examine(lock,fileinfo)){
X#ifdef DEBUG5
X dmsg(5,"Could not examine\n");
X#endif
X oserr=IoErr();
X goto fail;
X }
X if(fileinfo->fib_DirEntryType>=0){
X#ifdef DEBUG5
X dmsg(5,"ERROR: FILE is directory\n");
X#endif
X oserr=212;
X goto fail;
X }
X if(fileinfo->fib_Size==0){
X#ifdef DEBUG6
X dmsg(6,"ERROR: SIZE==0\n");
X#endif
X oserr=212;
X goto fail;
X }
X
X if( (doc->body=(struct textbody *)AllocMem(sizeof(struct textbody),MEMF_CLEAR|MEMF_NAMED,"readfile textbody"))==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not alloc textbody size");
X#endif
X goto fail;
X }
X doc->body->length=fileinfo->fib_Size;
X
X if(strncpy(doc->body->comment,fileinfo->fib_Comment,COMWIDTH)==0) {
X (void)strncpy(doc->body->comment,name,COMWIDTH);
X }
X doc->body->comment[COMWIDTH-1]=0;
X if (fileinfo) FreeMem(fileinfo,sizeof(struct FileInfoBlock));
X fileinfo=0;
X if( (doc->body->text=(char *)AllocMem(doc->body->length,0|MEMF_NAMED,"readfile3"))==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not alloc body size=%ld, mem=%ld\n",doc->body->length,AvailMem(0));
X#endif
X goto fail;
X }
X doc->body->usecount++;
X
X if( (fh=Open(name,1005))==0){
X#ifdef DEBUG5
X dmsg(5,"Could not OPEN\n");
X#endif
X oserr=IoErr();
X goto fail;
X }
X UnLock(lock);
X len=Read(fh,doc->body->text,doc->body->length);
X if(len!=doc->body->length) {
X#ifdef DEBUG5
X dmsg(5,"getfile: Read failed, read %ld bytes out of %ld total length\n",len,doc->body->length);
X#endif
X oserr=IoErr();
X goto fail;
X }
X
X oserr=0;
X Close(fh);
X
X if(0==(doc->body->filename=(char *)AllocMem(strlen(name)+1,MEMF_NAMED,"readfilename"))) {
X#ifdef DEBUG5
X dmsg(5,"getfile: Could not save filename\n");
X#endif
X oserr=103;
X goto fail;
X }
X strncpy(doc->body->filename,name,strlen(name)+1);
X }
X return(doc);
X
Xfail:
X#ifdef DEBUG5
X dmsg(5,"getfile: ReadFile Failed!\n");
X#endif
X /* pause("WAITING..."); */
X if (lock) UnLock(lock);
X if (doc) {
X if(doc->body) {
X if(doc->body->usecount) doc->body->usecount--;
X /* NOTE: There is no need to check for paragraphs here. */
X if(doc->body->usecount==0) {
X if(doc->body->text) {
X FreeMem(doc->body->text,doc->body->length);
X doc->body->text=0;
X }
X if(doc->body->filename) {
X FreeMem(doc->body->filename,strlen(doc->body->filename)+1);
X }
X FreeMem(doc->body,sizeof(struct textbody));
X doc->body=0;
X }
X }
X FreeMem(doc,sizeof(struct doc));
X }
X if (fh) Close(fh);
X if (fileinfo) FreeMem(fileinfo,sizeof(struct FileInfoBlock));
X return(0);
X}
X
Xvoid
Xfreefile(doc)
X struct doc *doc;
X{
X int i;
X
X if(doc->body) {
X if(doc->body->usecount) doc->body->usecount--;
X if(doc->body->usecount==0) {
X if(doc->body->text) {
X FreeMem(doc->body->text,doc->body->length);
X doc->body->text=0;
X }
X if(doc->body->filename) {
X FreeMem(doc->body->filename,strlen(doc->body->filename)+1);
X }
X
X if(doc->body->font.ta_Name) {
X FreeMem(doc->body->font.ta_Name, strlen(doc->body->font.ta_Name)+1);
X }
X doc->body->font.ta_Name=0;
X FreeMem(doc->body,sizeof(struct textbody));
X doc->body=0;
X }
X }
X if(doc->labs && doc->lab_count) {
X FreeMem(doc->labs, sizeof(struct labels)*doc->lab_count);
X }
X doc->labs=0;
X for(i=0;i<doc->p_count;i++) {
X if(doc->p[i].count && doc->p[i].lines) {
X FreeMem(doc->p[i].lines, doc->p[i].count * sizeof(struct displaylines));
X doc->p[i].lines=0;
X }
X }
X FreeMem(doc->p,doc->p_count*sizeof(struct paragraph));
X doc->p=0;
X doc->body=0;
X
X /* if(doc->propwidth) { */
X /* FreeMem(doc->propwidth,256); */
X /* doc->propwidth=0; */
X /* } */
X FreeMem(doc,sizeof(struct doc));
X}
X
X
Xstruct doc *
Xpbreakfile(doc)
X struct doc *doc;
X{
X register u_char c, *begin, *body=doc->body->text;
X register u_long size=doc->body->length, marksize;
X u_char *markbody, *command, tmpchar;
X u_short c_len, flags=0, inc;
X u_short p_count=0, refmark=0;
X int i;
X struct paragraph *p=0;
X
X sleft=stop=swidth=sheight=-1;
X /* Check to see if this is a HyperHelp file ( Begins with a (@ @) )*/
X if(doc->body->usecount>1) return doc;
X else {
X if(ENVFont) {
X i=strlen(ENVFont->ta_Name)+1;
X doc->body->font = *ENVFont;
X doc->body->font.ta_Name = (STRPTR)AllocMem(i,0|MEMF_NAMED,"pbreak0");
X if(doc->body->font.ta_Name==0) {
X doc->body->font.ta_YSize=0;
X } else {
X strncpy(doc->body->font.ta_Name,ENVFont->ta_Name,i);
X }
X }
X begin=body;
X if( size>1 && body[0]=='(' && body[1]=='@' ) {
X flags=DOC_FORMATED;
X
X while(size>0) {
X switch( c=*body++ ) {
X case 0:
X *body=32;
X break;
X case '\t':
X break;
X case '\n':
X *(body-1) = 32;
X if( *body=='\n' && size>1 ) {
X *(body-1)=0;
X *body=0;
X p_count++;
X size--;
X body++;
X }
X break;
X case '(':
X if(*body=='@' && size>1 ) {
X markbody = body-1;
X marksize = size;
X /* *(body-1) = 0; */
X command=body+1;
X size-=2;
X c_len=0;
X inc=1;
X while(size>0) {
X if(*body<=' ') {
X *body=' ';
X if(inc!=0) {
X inc=0;
X c_len--;
X }
X body++;
X } else if( *body == '@' && (*(body+1) == ')' && size>1)) {
X body++;
X break;
X } else if( *body++ == '(' && (*body == '@' && size>1)) {
X body=markbody+2;
X size = marksize -1;
X marksize=0;
X#ifdef DEBUG6
X dmsg(6,"getfile: NESTED COMMAND NOT ALLOWED!\n");
X#endif
X break;
X }
X size--;
X c_len+=inc;
X }
X if(size==0 || marksize==0) { /* ERROR Reached EOF before finding '@)' */
X#ifdef DEBUG6
X if(marksize!=0) dmsg(6,"getfile: ERROR -- no closeing '@)'.\n");
X#endif
X break;
X }
X *body = 1;
X if(c_len>1)tmpchar = token(command,c_len-1);
X if(c_len<=1 || tmpchar!=0) {
X *(body-1)=0; /* set a null byte for end of string*/
X markbody[0]=0; /* set open paren to \0 */
X *(command-1) = body-command+3;
X switch(tmpchar) {
X case 0:
X tmpchar=STYLE_INVALID;
X break;
X case STYLE_NORMAL:
X case STYLE_UNDERLINE:
X case STYLE_BOLD:
X case STYLE_ITALIC:
X case STYLE_COLOR:
X break;
X case STYLE_WINDOW:
X {
X u_char *ptr;
X int top=TOP,left=LEFT,width=WIDTH,height=HEIGHT;
X
X ptr=scannum(command+7,&top);
X ptr=scannum(ptr,&left);
X ptr=scannum(ptr,&width);
X ptr=scannum(ptr,&height);
X if(top+height<=screenHEIGHT && left+width<=screenWIDTH) {
X dmsg(1,"Setting top=%ld, height=%ld.\n",top,height);
X dmsg(1,"Setting left=%ld, width=%ld.\n",left,width);
X sleft=left;
X stop=top;
X swidth=width;
X sheight=height;
X }
X }
X break;
X case STYLE_REF:
X case STYLE_EXEC:
X if(refmark) {
X#ifdef DEBUG6
X dmsg(6,"getfile: Error, nested REFs not allowed\n");
X#endif
X tmpchar=STYLE_INVALID;
X } else refmark=1;
X break;
X case STYLE_UNREF:
X if(refmark)
X refmark=0;
X else {
X#ifdef DEBUG6
X dmsg(6,"getfile: UNREF missing matching REF or EXECUTE\n");
X#endif
X tmpchar=STYLE_INVALID;
X }
X break;
X case STYLE_FONT:
X /* (@font topaz.font 8@) */
X if (!NoSetFont) {
X int j,t=0;
X for(j=5;command[j]!=0 && command[j]!=' ';j++);
X /* j-=5; */
X if(doc->body->font.ta_Name) {
X FreeMem(doc->body->font.ta_Name, strlen(doc->body->font.ta_Name)+1);
X }
X doc->body->font.ta_Name = (STRPTR) AllocMem(j-4,0|MEMF_NAMED,"pbreak1");
X if(doc->body->font.ta_Name) {
X strncpy(doc->body->font.ta_Name,command+5,j-5);
X doc->body->font.ta_Name[j-5]=0;
X#ifdef DEBUG1
X dmsg(1,"getfile: Font name is '%s'\t",doc->body->font.ta_Name);
X#endif
X while(command[j]==' ')j++;
X while(command[j]<='9' && command[j]>='0') {
X t=t*10+ command[j]-'0';
X j++;
X }
X doc->body->font.ta_YSize=t;
X#ifdef DEBUG1
X dmsg(1,"getfile: Font height =%ld.\n",t);
X#endif
X }
X }
X break;
X case STYLE_TITLE:
X /* (@title This windows title */
X strncpy(doc->body->comment,command+6,COMWIDTH);
X doc->body->comment[COMWIDTH-1]=0;
X break;
X case STYLE_LSPACE:
X if(command[7]>='0' && command[7]<='9') {
X doc->linespace = (command[7]-'0');
X#ifdef DEBUG1
X dmsg(1,"getfile:linespace set to %ld.\n",doc->linespace);
X#endif
X }
X break;
X case STYLE_INDENT:
X case STYLE_PINDENT:
X break;
X case STYLE_LABEL:
X doc->lab_count++;
X break;
X default:
X#ifdef DEBUG9
X dmsg(9,"ERROR: GETFILE.c -> Unknown STLYE=%lx.\n",tmpchar);
X#endif
X break;
X }
X *command++=tmpchar;
X body++;
X } else {
X#ifdef DEBUG6
X dmsg(6,"getfile: UNRECOGNIZED COMMAND c_len=%ld, tmpchar=%ld\n",c_len,tmpchar);
X#endif
X body++;
X }
X }
X break;
X default:
X if(c<32) {
X#ifdef DEBUG6
X dmsg(6,"getfile: ERROR Illegal character 0x%lx in textfile.\n",(long)c);
X#endif
X *(body-1)=0;
X }
X break;
X }
X size--;
X } /* end while(size>0) for formatted text */
X } else {
X while(size>0) {
X switch( c=*body++ ) {
X case '\n':
X *(body-1)=0;
X p_count++;
X break;
X case '\t':
X break;
X default:
X if( c<32) {
X *(body-1)=32;
X }
X break;
X }
X size--;
X }
X }
X }
X#ifdef DEBUG"\33[32mPBREAK\33[31m SIZE=%ld
X /* dmsg("\33[32mPBREAK\33[31m SIZE=%ld, body-begin=%ld\n",size,body-doc->body); */
X#endif
X p=(struct paragraph *)AllocMem(sizeof(struct paragraph)*(p_count+1),MEMF_CLEAR|MEMF_NAMED,"pbreak2");
X if(p==0) {
X goto fail;
X }
X#ifdef DEBUG1
X dmsg(1,"p=%lx, doc=%lx, doc->body=%lx end=%lx ",p,doc,doc->body, doc->body+doc->body->length);
X#endif
X#ifdef DEBUG1
X dmsg(1,"Pcount=%ld\n",p_count);
X#endif
X doc->p = p;
X doc->p_count=p_count+1;
X body=doc->body->text;
X doc->p[0].data=body;
X doc->flags |= flags;
X for(i=1;i<=p_count;i++) {
X if(flags & DOC_FORMATED) {
X while(*body!=0 || *(body+1)!=0) {
X body++;
X }
X doc->p[i-1].length=body- doc->p[i-1].data;
X body++;
X } else {
X while(*body!=0 ) {
X body++;
X }
X doc->p[i-1].length=body- doc->p[i-1].data;
X }
X body++;
X doc->p[i].data=body;
X }
X i--;
X doc->p[i].length= ((long)doc->body->text)+doc->body->length-(long)body;
X#ifdef DEBUG1
X dmsg(1,"i=%ld, LastLen=%ld\n",i,doc->p[i].length);
X#endif
X /*
X {
X int j;
X for(j=doc->p[i].length-1;j>=0;j--) {
X if(doc->p[i].data[j]<32) doc->p[i].length--; else break;
X }
X }
X */
X return(doc);
X
Xfail:
X#ifdef DEBUG1
X dmsg(1,"getfile: PBREAK FAILED\n");
X#endif
X if(doc && doc->body->font.ta_Name) {
X FreeMem(doc->body->font.ta_Name, strlen(doc->body->font.ta_Name)+1);
X doc->body->font.ta_Name=0;
X }
X
X return(0);
X}
X
Xu_char *
Xscannum(ptr, num)
X u_char *ptr;
X int *num;
X{
X register int n=0;
X if(ptr==0) return 0;
X while(*ptr==' ' || *ptr=='\t') ptr++;
X if (!(*ptr>='0' && *ptr<='9')) return 0;
X while(*ptr>='0' && *ptr<='9') {
X n = n*10+ ptr[0]-'0';
X ptr++;
X }
X *num=n;
X while(*ptr==' ' || *ptr=='\t') ptr++;
X if(*ptr==',' || *ptr=='/') ptr++;
X if(*ptr==0) return 0;
X dmsg(1,"Scan returns n=%ld.\n",n);
X return ptr;
X}
X
SHAR_EOF
echo "extracting grandcentral.c"
sed 's/^X//' << \SHAR_EOF > grandcentral.c
X/* HyperHelp -- Copyright 1989 Joe Porkka */
X
X/* grandcentral.c -- The "main" loop of the program. Handles all the
X input events, and manages the windows
X*/
X
X/* #define DEBUG1 */
X#include <intuition/intuition.h>
X#include <exec/io.h>
X#include <exec/memory.h>
X#include "help.h"
X#include "helptext.h"
Xextern int ScreenType;
Xextern struct NewWindow nw;
Xextern int debug;
Xextern char *RootFile;
Xextern struct Screen *screen;
Xextern struct List windowhead;
Xextern short windowcount;
Xextern struct MsgPort *mp;
X
Xextern ULONG ENVRefresh, ENVNumClicks, ENVAskFirst;
Xextern struct Task *mytask;
X
X/* From print.c */
Xextern struct IOStdReq *printreq;
Xint printing, printbuflen;
Xu_char *printbuf;
Xstruct openwindows *printow;
X
X#define SETREFRESH(ow) ((struct openwindows *)ow)->flags|=ow_REFRESH
X#define CLRREFRESH(ow) ((struct openwindows *)ow)->flags&=~ow_REFRESH
X
X#define KEY_UP 0x4c
X#define KEY_DOWN 0x4d
X#define KEY_RIGHT 0x4e
X#define KEY_LEFT 0x4f
X#define KEY_ESC 0x45
X#define KEY_C 0x33
X
X#define QUAL_SHIFT 0X003
X#define QUAL_CTRL 0X008
X#define QUAL_ALT 0X030
X#define QUAL_REPT 0X200
X
Xextern ULONG lastclicksecs, lastclickmicros; /* From GC2.C */
Xshort openroot, closeall, hideall, goaway, findabout;
XULONG prevsecs=0, prevmicros=0;
Xu_short clickx, clicky, clickcount;
Xstruct key key;
Xint wide, high;
Xshort checkflags;
X
Xint
Xgrandcentral()
X{
X struct openwindows *tmpow, *ow;
X struct IntuiMessage *im, *im2, *succ, *GetMsg();
X unsigned long sigs;
X short countdown,dir;
X ULONG Class;
X USHORT Code;
X USHORT Qualifier;
X
X lastclicksecs = lastclickmicros =0;
X prevsecs=0, prevmicros=0;
X openroot=1; /* make the root file open immediatly */
X closeall=0; hideall=0; goaway=0; findabout=0;
X countdown=0; dir=0; checkflags=0;
X printing=0; printow=0; printbuf=0; printbuflen=0;
X printreq=0;
X
X do {
X if(closeall) {
X closeall=0;
X hideall=0;
X openroot=1;
X#ifdef DEBUG1
X dmsg(1,"Closing all windows!\n");
X#endif
X closeallwindows();
X#ifdef DEBUG1
X dmsg(1,"All closed, waiting for hotkey.\n");
X#endif
X if(waitforhotkey()==0) return 0;
X }
X
X if(goaway) {
X goaway=0;
X return 0; /* Cause main() to call die() to clean things up */
X }
X if(hideall) {
X closeall=0;
X hideall=0;
X#ifdef DEBUG1
X dmsg(1,"Hideing all windows\n");
X#endif
X for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
X if(!(ow->flags & ow_PRINTING)) {
X getdims(ow);
X CWS(ow->window, ow->doc->savefont);
X ow->window=0;
X }
X }
X if(screen) {
X CloseScreen(screen);
X screen=0;
X }
X#ifdef DEBUG1
X dmsg(1,"Waiting for hot key\n");
X#endif
X if(waitforhotkey()==0) return 0;
X#ifdef DEBUG1
X dmsg(1,"Got hot key, opening windows\n");
X#endif
X if(ScreenType!=0 && screen==0) customscreen();
X
X checkflags=0;
X for(ow=(struct openwindows*)windowhead.lh_Head ; ow->node.ln_Succ; ow=ow->node.ln_Succ) {
X if(!(ow->flags & ow_PRINTING)) {
X flipwindow(ow,1);
X checkflags++;
X }
X }
X#ifdef DEBUG1
X dmsg(1,"Windows all open!\n");
X#endif
X if(windowcount==0) {
X#ifdef DEBUG1
X dmsg(1,"Failed to open any windows :-( \n");
X#endif
X return 0;
X }
X Signal(mytask,0x80000000); /* Make sure we get to the GetMsg() call */
X }
X if(openroot){
X openroot=0;
X closeall=hideall=0;
X ow=getfile(RootFile);
X if(ow==0 && windowcount==0) {
X#ifdef DEBUG1
X dmsg(1,"Could not open initial file.");
X#endif
X return 0;
X }
X refresh(ow);
X }
X if(checkflags) {
X#ifdef DEBUG1
X dmsg(1,"$=%ld ",checkflags);
X#endif
X for(tmpow=(struct openwindows *)windowhead.lh_Head;tmpow->node.ln_Succ;tmpow=tmpow->node.ln_Succ) {
X if(tmpow->window && tmpow->flags & ow_REFRESH) {
X if(checkflags) checkflags--;
X refresh(tmpow);
X tmpow->flags&=~ow_REFRESH;
X }
X if((!printing) && tmpow->window && tmpow->flags & (ow_PRINTFILE | ow_PRINTWINDOW)) {
X static UBYTE *wt, *st;
X static int test;
X static char *printwait="Opening printer.device";
X
X if(checkflags) checkflags--;
X printing=0; /* Just to be sure. */
X wt=tmpow->window->Title;
X st=tmpow->window->ScreenTitle;
X SetWindowTitles(tmpow->window,printwait,printwait);
X test=printinit(mp);
X SetWindowTitles(tmpow->window,wt,st);
X if(test==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not init printer!\n");
X#endif
X tmpow->flags&= ~(ow_PRINTFILE | ow_PRINTWINDOW);
X } else {
X if(tmpow->flags & ow_PRINTWINDOW) {
X high=tmpow->high;
X wide=tmpow->wide;
X } else {
X getprintwidth(&wide, &high);
X high=0;
X }
X tmpow->flags&= ~(ow_PRINTFILE | ow_PRINTWINDOW);
X printbuf=(u_char *)AllocMem(wide+wide,MEMF_NAMED,"Print buffer");
X if(printbuf==0) {
X#ifdef DEBUG5
X dmsg(5,"No mem for print buf!\n");
X#endif
X printdnit();
X } else {
X printbuflen=wide+wide;
X printow=getprintfile(tmpow->doc->body->filename,wide);
X#ifdef DEBUG1
X dmsg(1,"GOTFILE!! WINDOWCOUNT=%ld.\n",windowcount);
X#endif
X if(printow==0) {
X#ifdef DEBUG5
X dmsg(5,"Could not getprintfile!\n");
X#endif
X printdnit();
X } else {
X printow->flags |= ow_PRINTING;
X#ifdef DEBUG1
X dmsg(1,"Sending FIRST printmessage\n");
X#endif
X printit("\033#1"); /* reinitialize aRIN */
X printing=1;
X if(high) { /* Set begining position if printing from window */
X printow->doc->pnum=tmpow->doc->pnum;
X printow->doc->lnum=tmpow->doc->lnum;
X }
X }
X }
X }
X }
X }
X }
X /* pause("Wait for input signal"); */
X if(windowcount==0) {
X#ifdef DEBUG1
X dmsg(1,"Attempt to wait while no windows open.\n");
X#endif
X return 0;
X }
X sigs=Wait(-1);
X while( (im=GetMsg(mp))!=0) {
X#ifdef DEBUG1
X dmsg(1,"LOOP ");
X#endif
X if( (printreq==(struct IOStdReq *)im) && printing && printreq) {
X if(printreq->io_Error) {
X#ifdef DEBUG5
X dmsg(5,"print error!\n");
X#endif
X printing=5;
X }
X switch(printing) {
X case 1: /* Just put out the aRIN, now put the filename */
X printit(printow->doc->body->filename);
X printing=2;
X break;
X case 2: /* Now put out a cr */
X printit("\n");
X printing=3;
X break;
X case 3:
X displayline(0,&printow->doc->p[printow->doc->pnum],printow->doc->lnum,printow,printbuf,printbuflen);
X printit(printbuf);
X printing=2;
X printow->doc->lnum++;
X if(printow->doc->lnum >= printow->doc->p[printow->doc->pnum].count) {
X printow->doc->lnum=0;
X printow->doc->pnum++;
X if(printow->doc->pnum >= printow->doc->p_count) {
X printing=4; /* end of doc */
X }
X }
X if(high) {
X high--;
X if(high==0) printing=4; /* End of window */
X }
X break;
X case 4: /* Now put out a cr, FF, aRIN */
X printit("\n\14\33#1");
X printing=5;
X break;
X case 5: /* Stop printing */
X xcancelprintjob:
X#include "kludge.h"
X /* cancelprintjob(); /* This call calls the guru, so inline the function */ */
X printing=0;
X#ifdef DEBUG1
X dmsg(1," GC %ld %ld %ld \n",printing,printreq,printbuf);
X#endif
X break;
X case 6: /* Abort all printing */
X printit("\33c"); /* Hard reset, to empty buffer */
X printing=7;
X break;
X case 7: /* Now remove any pending jobs */
X for(tmpow=(struct openwindows*)windowhead.lh_Head ; tmpow->node.ln_Succ; tmpow=tmpow->node.ln_Succ) {
X tmpow->flags &= ~(ow_PRINTFILE | ow_PRINTWINDOW);
X }
X#ifdef DEBUG1
X dmsg(1,"Now removeing current job.\n");
X#endif
X goto xcancelprintjob; /* To avoid too many copies
X of kludge.h
X */
X /* break; */
X }
X continue;
X }
X tmpow= (struct openwindows *)im->IDCMPWindow->UserData;
X Class=im->Class;
X Code=im->Code;
X Qualifier=im->Qualifier;
X if(Class==RAWKEY) {
X switch(Code) {
X case KEY_UP:
X Class=GADGETDOWN;
X im->IAddress = (APTR) tmpow->up;
X break;
X case KEY_DOWN:
X Class=GADGETDOWN;
X im->IAddress = (APTR)tmpow->down;
X break;
X case KEY_UP+128:
X Class=GADGETUP;
X im->IAddress = (APTR)tmpow->up;
X break;
X case KEY_DOWN+128:
X Class=GADGETUP;
X im->IAddress = (APTR)tmpow->down;
X break;
X default:
X Code=0;
X Class=0;
X break;
X } /* Switch (Code) */
X /* Remove excess repeat keys from Message port */
X if (im->Qualifier & QUAL_REPT) {
X Forbid();
X im2 = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
X while ( succ=(struct IntuiMessage *)im2->ExecMessage.mn_Node.ln_Succ ) {
X if ( im!=im2 && im2->Class==RAWKEY && (im2->Qualifier & QUAL_REPT) ) {
X Remove ( im2 );
X ReplyMsg( im2 );
X }
X im2 = succ;
X }
X Permit();
X }
X } /* if (Class == RAWKEY) */
X switch(Class) {
X case 0:
X break; /* Ignore NULL Class */
X case MOUSEMOVE:
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X scrollit(tmpow);
X break;
X case GADGETDOWN:
X#ifdef DEBUG1
X /* dmsg(1,"GADGETDOWN '%s', #%ld.\n",im->IDCMPWindow->Title,(long) ((struct Gadget *)im->IAddress)->GadgetID); */
X#endif
X countdown=7; /* .7 second initial delay */
X switch( ((struct Gadget *)im->IAddress)->GadgetID ) {
X case SCROLLBAR:
X#ifdef DEBUG1
X /* dmsg(1,"SCROLL BAR!\n"); */
X#endif
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X scrollit(tmpow);
X break;
X case UPARROW:
X dir=-1;
X if(Qualifier & QUAL_SHIFT) dir= -tmpow->high;
X move( tmpow,dir);
X if(dir<-1 || ENVRefresh!=SMART_REFRESH) {
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X SETREFRESH(tmpow);
X }
X fixscrollgadget(tmpow);
X ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags | INTUITICKS);
X break;
X case DOWNARROW:
X dir=1;
X if(Qualifier & QUAL_SHIFT) dir=tmpow->high;
X move(tmpow, dir);
X if(dir>1 || ENVRefresh!=SMART_REFRESH) {
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X SETREFRESH(tmpow);
X }
X fixscrollgadget(tmpow);
X ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags | INTUITICKS);
X break;
X default:
X break;
X }
X break;
X case INTUITICKS:
X if(countdown) {
X countdown--;
X if(countdown==0) {
X ReplyMsg(im);
X if(dir<0) {
X if( tmpow->up->Flags & SELECTED) {
X move(tmpow,dir);
X fixscrollgadget(tmpow);
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X SETREFRESH(tmpow);
X countdown=2;
X }
X } else if(dir>0) {
X if( tmpow->down->Flags & SELECTED) {
X move( tmpow,dir);
X fixscrollgadget(tmpow);
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X SETREFRESH(tmpow);
X countdown=2;
X }
X }
X im=0;
X }
X } else {
X ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags & (~INTUITICKS));
X }
X break;
X case GADGETUP:
X#ifdef DEBUG1
X dmsg(1,"GADGETUP '%s', #%ld.\n",im->IDCMPWindow->Title,(long) ((struct Gadget *)im->IAddress)->GadgetID);
X#endif
X if( ((struct Gadget *)im->IAddress)->GadgetID ==ICONWINDOW) {
X if (! (tmpow->flags & ow_REFRESH)) checkflags++;
X if(flipwindow(tmpow,0)==0) goto caseclosewindow;
X im=0;
X } else {
X ModifyIDCMP(im->IDCMPWindow,im->IDCMPWindow->IDCMPFlags & (~INTUITICKS));
X }
X break;
X case MENUPICK:
X#ifdef DEBUG1
X dmsg(1,"MENU PICK ");
X#endif
X processmenuevent(Code, tmpow->window->MenuStrip, tmpow);
X if(findabout) {
X findabout=0;
X about(tmpow->window);
X }
X break;
X case SIZEVERIFY:
X#ifdef DEBUG1
X dmsg(1,"** SIZEVERIFY **\n");
X#endif
X break;
X case NEWSIZE:
X tmpow->flags |= ow_SIZED; /* Tell refresh() to update entire window */
X /* Prevent another resize, and save the windows' size, then continue */
X getdims(tmpow);
X
X#ifdef DEBUG1
X dmsg(1,"** NEWSZ **\n");
X#endif
X if(sizewindow(im->IDCMPWindow)!=0) {
X break;
X }
X /* refresh(tmpow); */
X#ifdef DEBUG5
X dmsg(5,"****ERROR grandcentral(): size operation failed, closeing window.\n");
X#endif
X /* NOTE: The break is intentionally missing */
X case CLOSEWINDOW:
Xcaseclosewindow:
X#ifdef DEBUG1
X dmsg(1,"Case closewindow\n");
X#endif
X ReplyMsg(im);
X closewindow(tmpow);
X im=0;
X tmpow=0;
X break;
X case REFRESHWINDOW:
X if( tmpow->flags & ow_SIZED) {
X /* Clear the damage list, then update the window */
X BeginRefresh(im->IDCMPWindow);
X EndRefresh(im->IDCMPWindow,-1);
X cleardisplay(tmpow);
X refresh(tmpow );
X tmpow->flags &= ~ ow_SIZED;
X } else {
X BeginRefresh(im->IDCMPWindow);
X refresh(tmpow );
X EndRefresh(im->IDCMPWindow,-1);
X }
X break;
X case MOUSEBUTTONS:
X switch(Code) {
X case SELECTDOWN:
X#ifdef DEBUG1
X dmsg(1,"LEFT DOWN\n");
X#endif
X checkclicks(im,tmpow);
X break;
X case SELECTUP:
X#ifdef DEBUG1
X dmsg(1,"LEFT UP\n");
X#endif
X countdown=0;
X break;
X default:
X break;
X }
X break;
X default:
X#ifdef DEBUG9
X dmsg(9,"Unknown IntuiMessage->Class=%08lx\n",Class);
X#endif
X break;
X }
X if(im) ReplyMsg(im);
X }
X } while( windowcount && !(sigs & 4096));
X return 1;
Xfail:
X return 0;
X}
SHAR_EOF
echo "extracting help.h"
sed 's/^X//' << \SHAR_EOF > help.h
X/* HyperHelp -- Copyright 1989 Joe Porkka */
X
X/* help.h -- Useful #defines and typedefs + a couple of structs
X and function prototypes for everything.
X*/
X
Xtypedef unsigned short u_short;
Xtypedef unsigned int u_int;
Xtypedef unsigned long u_long;
Xtypedef unsigned char u_char;
Xtypedef unsigned char u_byte;
X
X#define DEBUG9
X#define DEBUG99
X#define DEBUG10
X
X#define AllocMem allocmem
X#define FreeMem freemem
X#define MEMF_NAMED 0x10000000
X
X#define SCROLLBAR 1
X#define UPARROW 2
X#define DOWNARROW 3
X#define ICONWINDOW 4
X#define HELPICONWINDOWFLAGS WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | SIMPLE_REFRESH | NOCAREREFRESH
X#define HELPWINDOWFLAGS WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | SIZEBRIGHT | ACTIVATE | WINDOWSIZING
X
X#define HELPICONWINDOWIDCMPFLAGS CLOSEWINDOW | MOUSEBUTTONS | GADGETUP | MENUPICK
X#define HELPWINDOWIDCMPFLAGS CLOSEWINDOW | MOUSEBUTTONS | MOUSEMOVE | GADGETDOWN | GADGETUP | NEWSIZE | REFRESHWINDOW | RAWKEY | MENUPICK
X
X#define HELPWINDOWLIST 'HELP'
X#define MINX 176
X#define MINY 55
X#define TABSTOP 8
X
Xstruct key {
X u_short length, type; /* type==0 file, type!=0 execute */
X u_char *name;
X};
Xstruct DOSerror {
X int number;
X char *text;
X};
X
X/* Functions in "main.c" */
Xvoid main(int, char *);
Xint startup();
Xvoid shutdown();
Xvoid die(char *);
Xvoid closewindow(struct openwindows *); /* Should be in windows.c */
X
X/* Functions in "images.c" */
Xvoid getimages( USHORT **, USHORT **, USHORT **);
X
X/* Functions in "windows.c" */
Xvoid CWS(struct Window *, struct TextFont *);
Xstruct Window *makewindow(struct openwindows *,int,int,int,int,u_char *, struct TextAttr *);
Xstruct Window *OpenWindow(struct NewWindow *);
Xvoid closewindowsafely(struct openwindows *);
Xint sizewindow(struct Window *);
Xvoid fixscrollgadget(struct openwindows *);
Xvoid refresh(struct openwindows *);
X
X/* Functions in "move.c" */
Xvoid moveto(struct openwindows*, int);
Xvoid move(struct openwindows*,int);
Xint currentlinenum(struct doc *);
X
X/* Functions in "fileinit.c" */
Xint fileinit(void);
X
X/* Functions in "format.c" */
Xint format(struct doc *, int , struct RastPort *);
X
X/* Functions in "gen.c" */
Xchar *arg(int *, char **);
Xint strncpy(char *, char *, int), strlen(char *);
Xint strcmp(char *,char *), strnicmp(char *, char *, int);
Xu_char *strchr(u_char *, u_char);
Xint strfind(char *, char *);
X
X/* Functions in "getfile.c" */
Xstruct openwindows *getfile(u_char *);
Xstruct openwindows *getprintfile(u_char *,int);
Xstruct doc *getdatafile(u_char *);
Xstruct doc *readfile(char *);
Xvoid freefile(struct doc *);
Xu_char token(u_char *, u_long );
Xstruct doc *pbreakfile(struct doc *);
Xu_char *scannum(u_char *, int *);
X
X/* Functions in "displayline.c" */
Xvoid displayline(struct RastPort *,struct paragraph *, u_short, struct openwindows *, u_char *, int);
Xvoid indentbuf(u_char **, int *, int);
Xvoid copyintobuf(u_char, u_char **, int *, u_char *, int);
X
X/* Functions in "findwordinline.c" */
Xvoid findword(struct openwindows *, int, int, struct key *);
Xint findwordinline(struct paragraph *,u_short,short, struct key *, u_short *, int);
X
X/* Functions in "grandcentral.c" */
Xint grandcentral();
X
X/* Functions in "gc2.c" */
Xint flipwindow(struct openwindows *, int);
Xvoid getdims(struct openwindows *);
Xvoid scrollit(struct openwindows *);
Xvoid processmenuevent(USHORT, struct Menu *, struct openwindows *);
Xvoid checkclicks(struct IntuiMessage *, struct openwindows *);
X
X/* Functions in "index.c" */
Xu_char *lookup(u_long, u_char *, int);
Xvoid index(u_char *, struct key *);
Xu_long openindexfile(u_char *);
Xvoid closeindexfile(u_long);
X
X/* Functions in "oserr.c" */
Xint errnum(int);
X
X/* Functions in "menu.c" */
Xvoid makemenu(struct Window *);
Xvoid removemenu(struct Window *);
Xvoid initmenus(struct Window *);
Xvoid domenu(struct Menu *, BYTE *, int *);
Xvoid domenuitem(struct Menu *, struct MenuItem *, struct IntuiText *, BYTE *, BYTE, int *);
X
X/* Functions in "print.c" */
Xint printinit(struct MsgPort *);
Xvoid getprintwidth(int *, int *);
Xvoid printit(u_char *);
Xvoid printdnit(void);
X
X/* Retired Functions */
Xstruct doc *formatfile(struct RemoveThisDef, struct doc *);
Xint linebreakfile(struct RemoveThisDef, struct doc *, int);
Xvoid printline(struct RemoveThisDef, struct paragraph *, u_short);
Xchar *docommand(struct RemoveThisDef, u_char **, u_long *);
SHAR_EOF
echo "End of archive 2 (of 3)"
# if you want to concatenate archives, remove anything after this line
exit